package com.xiaocheng.core.memento;

import java.util.ArrayList;
import java.util.List;

public class Creater {
	private List<MementoInterface> mementoInterfaces;
	private Originator originator;
	private int index;
	public Creater(Originator originator){
		this.mementoInterfaces = new ArrayList<>();
		this.originator = originator;
		this.index = -1;
	}
	public Originator getOriginator() {
		return originator;
	}
	 /**
     * 创建一个新的检查点
     */
    public int createMemento(){
        MementoInterface memento = originator.createMemento();
        mementoInterfaces.add(memento);
        return index++;
    }
    /**
     * 将发起人恢复到某个检查点
     */
    public void restoreMemento(int index){
        MementoInterface memento = mementoInterfaces.get(index);
        originator.restoreMemento(memento);
    }
	public int getIndex() {
		return index;
	}
	
	

}
